home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / Advanced I⁄O v2.3 / ANSI #includes addenda / ostream < prev    next >
Text File  |  1996-02-01  |  3KB  |  124 lines

  1. // ostream standard header
  2. #ifndef _OSTREAM_
  3. #define _OSTREAM_
  4. #include <streambuf>
  5.  
  6. #if __MWERKS__
  7. #pragma options align=mac68k
  8.  
  9. #if __CFM68K__ && __USING_IMPORTED_ANSI__
  10. #pragma import on
  11. #endif
  12. #endif
  13.  
  14.         // class ostream
  15. class ostream : virtual public ios {
  16. public:
  17.     ostream(streambuf *_S)
  18.            { init(_S); }
  19.     ostream(_Uninitialized)
  20.         : ios(_Noinit) {}
  21.     virtual ~ostream();
  22.     _Bool opfx();
  23.     void osfx();
  24.     ostream& operator<<(ostream& (*_F)(ostream&))
  25.         {return ((*_F)(*this)); }
  26.     ostream& operator<<(ios& (*_F)(ios&))
  27.         {(*_F)(*(ios *)this); return (*this); }
  28.     ostream& operator<<(const char *);
  29.     ostream& operator<<(char _C)
  30.         {put(_C); return (*this); }
  31.     ostream& operator<<(unsigned char _C)
  32.         {return (*this << (char)_C); }
  33.     ostream& operator<<(short _X)
  34.         {return (_Print(&"B hoB hxB hd"[_If()], _X)); }
  35.     ostream& operator<<(unsigned short _X)
  36.         {return (_Print(&"B hoB hxB hu"[_If()], _X)); }
  37.     ostream& operator<<(int _X)
  38.         {return (_Print(&"B  oB  xB  d"[_If()], _X)); }
  39.     ostream& operator<<(unsigned int _X)
  40.         {return (_Print(&"B  oB  xB  u"[_If()], _X)); }
  41.     ostream& operator<<(long _X)
  42.         {return (_Print(&"B loB lxB ld"[_If()], _X)); }
  43.     ostream& operator<<(unsigned long _X)
  44.         {return (_Print(&"B loB lxB lu"[_If()], _X)); }
  45.     ostream& operator<<(float _X)
  46.         {return (_Print(&"P. eP. fP. g"[_Ff()], _Pr(), _X)); }
  47.     ostream& operator<<(double _X)
  48.         {return (_Print(&"P.leP.lfP.lg"[_Ff()], _Pr(), _X)); }
  49.     ostream& operator<<(long double _X)
  50.         {return (_Print(&"P.LeP.LfP.Lg"[_Ff()], _Pr(), _X)); }
  51.     ostream& operator<<(void *);
  52.     ostream& operator<<(streambuf&);
  53.     ostream& put(char);
  54.     ostream& write(const char *, int);
  55.     ostream& write(const unsigned char *_S, int _N)
  56.         {return (write((const char *)_S, _N)); }
  57.     ostream& flush();
  58. streampos tellp()
  59. {
  60.     streampos pos = rdbuf()->pubseekoff(0, ios::cur, ios::out);
  61.     if (pos == streampos(EOF))
  62.         setstate(ios::badbit);
  63.     return pos;
  64. }
  65. ostream& seekp(streampos pos)
  66. {
  67.     pos = rdbuf()->pubseekpos(pos, ios::out);
  68.     if (pos == streampos(EOF))
  69.         setstate(ios::badbit);
  70.     return *this;
  71. }
  72.  
  73. ostream& seekp(streamoff off, ios::seek_dir dir)
  74. {
  75.   streampos pos = rdbuf()->pubseekoff(off,dir,ios::out);
  76.   if (pos == streampos(EOF))
  77.     setstate(ios::badbit);
  78.   return *this;
  79. }
  80. #if _HAS_SIGNED_CHAR
  81.     ostream& operator<<(signed char _C)
  82.         {return (*this << (char)_C); }
  83.     ostream& write(const signed char *_S, int _N)
  84.         {return (write((const char *)_S, _N)); }
  85. #endif /* _HAS_SIGNED_CHAR */
  86. protected:
  87.     int _Ff()
  88.         {return ((flags() & floatfield) == scientific ? 0
  89.             : (flags() & floatfield) == fixed ? 4 : 8); }
  90.     int _If()
  91.         {return ((flags() & basefield) == oct ? 0
  92.             : (flags() & basefield) == hex ? 4 : 8); }
  93.     void _Pad(const char *, char *, int);
  94.     int _Pr();
  95.     ostream& _Print(const char *, ...);
  96.     };
  97.         // manipulators
  98. ostream& endl(ostream&);
  99. ostream& ends(ostream&);
  100. ostream& flush(ostream&);
  101.  
  102. #if __MWERKS__
  103. #if __CFM68K__ && __USING_IMPORTED_ANSI__
  104. #pragma import reset
  105. #endif
  106.  
  107. #pragma options align=reset
  108. #endif
  109.  
  110. #endif
  111.  
  112. /*
  113.  * Copyright (c) 1994 by P.J. Plauger.  ALL RIGHTS RESERVED. 
  114.  * Consult your license regarding permissions and restrictions.
  115.  */
  116.  
  117. /* Change log:
  118.  * 1994-06-04: PlumHall baseline
  119.  * 1994-09-30: Applied diffs for Fri Aug 26 00:51:20 1994
  120.  * 1994-10-07: Inserted MW changes.
  121.  * 1994-10-14: XL04 change istream(streambuf *_S) to init derived 
  122.  *//* Change log:
  123.  */
  124.